var e = require;
var o = module;
cc.Class({
    extends: cc.Component,
    properties: {colliderRoot: cc.Node, compose: cc.Node},
    onLoad: function onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
    },
    start: function start() {
        (this.selected = []), (this.composeData = []);
        for (var e = 0; e < this.compose._children.length; e++) {
            var o = this.compose._children[e],
                t = o.name.split("="),
                n = {q: t[0].split(","), a: t[1], n: o};
            this.composeData.push(n);
        }
        this.moveSpd = 30;
    },
    onTouchStart: function onTouchStart(e) {
        var o = this.checkBtnPolygonCollider(e);
        o && this.checkSelect(o);
    },
    checkBtnPolygonCollider: function checkBtnPolygonCollider(e) {
        for (var o = e.getLocation(), t = "", n = this.colliderRoot._children.length, i = 0; i < n; i++) {
            var r = this.colliderRoot._children[i].getComponent(cc.Collider).points,
                l = this.colliderRoot._children[i].convertToNodeSpaceAR(o);
            if (cc.Intersection.pointInPolygon(l, r)) {
                t = this.colliderRoot._children[i].name;
                break;
            }
        }
        return t;
    },
    checkSelect: function checkSelect(e) {
        var o = this.selected.indexOf(e),
            t = this.colliderRoot.getChildByName(e);
        o >= 0
            ? (this.selected.splice(o, 1),
              (t.color = cc.Color.BLACK),
              (t.zIndex = 0),
              soundMgr.playSound(soundMgr.unselected))
            : (this.selected.push(e), (t.color = cc.Color.RED), (t.zIndex = 1), soundMgr.playSound(soundMgr.selected));
    },
    reset: function reset() {
        for (var e = this.colliderRoot._children.length, o = 0; o < e; o++) {
            var t = this.colliderRoot._children[o];
            (t.color = cc.Color.BLACK), (t.zIndex = 0);
        }
        this.selected = [];
    },
    checkAnswer: function checkAnswer() {
        var e = null;
        if (this.selected.length)
            for (var o = 0; o < this.composeData.length; o++) {
                var t = this.composeData[o],
                    n = !0;
                if (t.q.length == this.selected.length)
                    for (var i = 0; i < this.selected.length; i++) {
                        var r = this.selected[i];
                        if (t.q.indexOf(r) < 0) {
                            n = !1;
                            break;
                        }
                    }
                else n = !1;
                n && (e = t);
            }
        return e;
    }
});
